<template>
  <div class="diary-bg">
    <div class="top"></div>
    <!-- 导航条 -->
    <van-nav-bar
      left-arrow
      @click-left="goHome"
      title="宠物日记"
      right-text="发布日记"
      @click-right="goUploaddairy"
      fixed
    />

    <!-- 日记 -->
    <div @click="goDetails(item.did)" v-for="item in diary" :key="item.index">
      <diary-cell :item="item" />
    </div>

    <div class="bottom"></div>
  </div>
</template>

<script>
import DiaryCell from "@/components/DiaryCell.vue";

export default {
  components: { DiaryCell },
  data() {
    return {
      diarycell: {},
      diary: [],
    };
  },
  mounted() {
    
    // console.log("拿到从发布页面传来的地址",this.fileAdd);
    this.axios.get("http://120.79.2.254:3000/diary").then((res) => {
      // console.log('日记页面',res);
      this.diary = res.data.result;
      // console.log(this.diary);
    });
    //查询宠物日记
    let a = {
      limit: 10,
      page: 1, //分页页码，数字类型
    };
    this.axios.post("client/queryDiary", a).then((res) => {
      // this.diarycell=res.data.data
      console.log("查询宠物日记接口12333333", res);
    });
  },
  methods: {
    goDetails(did) {
      this.axios
        .get(`http://120.79.2.254:3000/diaryID?did=${this.did}`)
        .then((res) => {
          console.log([101, res]);
          this.$router.push(`/details?did=${did}`);
        });
    },
    // 返回首页
    goHome() {
      this.$router.push("/home");
    },
    // 跳转发布页面
    goUploaddairy() {
      if (this.$store.state.isLogin) {
        this.$router.push("/uploaddairy");
      } else {
        this.$toast("您还没有登录，请先登录!");
        this.$router.push("/login");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
// 日记单元
.diary {
  width: 90vw;
  margin: auto;
  border-radius: 3vw;
  box-shadow: 0px 0px 6px #ccc;
  text-align: center;
  margin-bottom: 4vw;
  background-color: #fff;
  .da-title {
    width: 90%;
    height: 10vw;
    line-height: 10vw;
    display: flex;
    margin: auto;
    justify-content: space-between;
    margin-bottom: 6vw;
    padding-top: 3vw;
    .user {
      .head-img {
        width: 10vw;
        border-radius: 50%;
        margin-right: 2vw;
      }
      span {
        color: #000;
        font-size: 1em;
        font-weight: bold;
      }
    }
    .city {
      color: #a7a7a7;
      font-size: 0.8em;
    }
  }
  .content {
    margin: auto;
    width: 90%;
    height: 6vw;
    line-height: 6vw;
    font-size: 0.9em;
    overflow: hidden;
    white-space: nowrap; //强制不换行
    text-overflow: ellipsis;
    margin-bottom: 3vw;
  }
  .cover {
    width: 90%;
    border-radius: 3vw;
    margin-bottom: 5vw;
  }
}
.top {
  padding-top: 60px;
}
.bottom {
  height: 5vw;
}
// 左箭头
::v-deep .van-icon-arrow-left:before {
  color: #a7a7a7;
}

// 右文案
::v-deep .van-nav-bar__text {
  color: #f8e176;
  font-size: 1rem;
  // font-weight: bold;
}
</style>